<template>
  <el-table
    ref="table"
    height="330"
    stripe
    :data="data"
    :border="true"
    :highlight-current-row="true"
    @selection-change="onSelectChange"
  >
    <el-table-column
      type="selection"
      align="center"
      width="40"
    ></el-table-column>
    <el-table-column
      label="支行名称"
      prop="name"
      align="center"
      :show-overflow-tooltip="true"
    ></el-table-column>
    <el-table-column
      label="统一社会信用代码"
      prop="code"
      align="center"
      width="120"
      :show-overflow-tooltip="true"
    ></el-table-column>
    <el-table-column
      label="注册地址"
      prop="address"
      align="center"
      width="180"
      :show-overflow-tooltip="true"
    ></el-table-column>
    <el-table-column
      v-if="which"
      label="授权人"
      prop="authName"
      align="center"
      width="70"
    ></el-table-column>
    <el-table-column
      v-if="which"
      label="授权时间"
      prop="time"
      align="center"
      width="90"
      :show-overflow-tooltip="true"
    >
      <template slot-scope="{ row }">
        {{ formatTime(row.time) }}
      </template>
    </el-table-column>
    <el-table-column label="状态" align="center" width="60">
      <template slot-scope="{ row }">{{
        row.status === 0 ? "未授权" : "已授权"
      }}</template>
    </el-table-column>
    <el-table-column v-if="which" label="操作" align="center" width="80">
      <template slot-scope="scope">
        <el-button
          type="primary"
          plain
          size="mini"
          @click="cancelAuthor(scope)"
        >
          取消授权
        </el-button>
      </template>
    </el-table-column>
  </el-table>
</template>

<script>
import moment from "moment";
export default {
  name: "CollapseAuthGrid",
  inject: {
    searchQuery: {
      default: () => {},
    },
  },
  props: {
    data: {
      type: Array,
      default: () => [],
    },
    position: {
      type: String,
      default: () => "left",
    },
    defaultChecked: {
      type: Array,
      default: () => [],
    },
  },
  data() {
    return {
      value: [],
    };
  },
  computed: {
    which() {
      return this.position === "right";
    },
  },
  watch: {
    "searchQuery.searchText": function (val) {
      console.log(val)
    },
  },
  created() {},
  methods: {
    onSelectChange(selection) {
      this.$emit("checked-change", selection);
    },
    cancelAuthor(scope) {
      console.log(scope);
    },
    formatTime(date) {
      return moment(date).format("YYYY-MM-DD HH:mm:ss");
    },
  },
};
</script>